from typing import Union

import requests

from download import GenericDownloader
from enums import CourseType
from login import LoginHandler


class Client:
    def __init__(self, username: str, password: str):
        self.session = requests.Session()
        self.session.headers.update({
            "Referer": "https://www.imooc.com/",
            "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.79 Safari/537.36",
        })

        self.__login_handler = LoginHandler(self, username, password)
        self.__downloader = GenericDownloader(self)

    def login(self):
        return self.__login_handler.login()

    def download(self, course_id: Union[str, int], course_type: CourseType):
        return self.__downloader.download(course_id, course_type)
